package service

import (
	"context"
	"go-pioneer/internal/dtos"
	"go-pioneer/internal/repository"
	"go-pioneer/models"
)

type ExampleService interface {
	CreateExample(ctx context.Context, req dtos.ExampleReq) error
	GetExample(ctx context.Context, id string) (models.Example, error)
}

type exampleService struct {
	repo repository.ExampleRepository
}

func NewExampleService(repo repository.ExampleRepository) ExampleService {
	return &exampleService{
		repo: repo,
	}
}

func (s *exampleService) CreateExample(ctx context.Context, req dtos.ExampleReq) error {
	example := models.Example{
		Name: req.Name,
	}

	err := s.repo.CreateExample(ctx, example)
	if err != nil {
		return nil
	}

	return nil
}

func (s *exampleService) GetExample(ctx context.Context, id string) (models.Example, error) {
	example, err := s.repo.GetExample(ctx, id)
	if err != nil {
		return models.Example{}, nil
	}

	return example, nil
}
